package com.bodacn.keypoint;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.bodacn.keypoint.adapter.DetailAdapter;
import com.bodacn.keypoint.adapter.OrderBottomDetailAdapter;
import com.bodacn.keypoint.adapter.OrderDetailAdapter;
import com.bodacn.keypoint.adapter.StationAdapter;
import com.bodacn.keypoint.adapter.TaiorCheckAdapter;
import com.bodacn.keypoint.adapter.TaiorCheckBottomAdapter;
import com.bodacn.keypoint.bean.CutStation;
import com.bodacn.keypoint.bean.ODetail;
import com.bodacn.keypoint.bean.OrderDetailBean;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 裁剪呼叫
 */
public class FragmentP extends Fragment implements TaiorCheckBottomAdapter.OrderDetialOn, TaiorCheckAdapter.OrderDetialOn, OrderDetailAdapter.Detail, OrderBottomDetailAdapter.Detail {
    View view;

    public static final int MSG_ERRMSG = 9004;
    public static final int MSG_SCANBARCODE = 9005;
    public static final int MSG_Taior = 8001;
    public static final int MSG_Model = 8002;
    public static final int MSG_Clear = 8003;
    public static final int MSG_SEARCH = 9006;
    public static final int MSG_DETAIL = 90010;
    public static final int MSG_PUSH_AWAY_EMPTY = 9007;
    private final static int MSG_CallAgvResult = 9009;
    @BindView(R.id.txt_order)
    EditText txtOrder;
    @BindView(R.id.btn_refresh)
    Button btnRefresh;
    @BindView(R.id.btn_push_empty)
    Button btnPushEmpty;
    @BindView(R.id.btn_call_agv)
    Button btnCallAgv;
    @BindView(R.id.btn_clear)
    Button btnClear;
    @BindView(R.id.btn_task_list)
    Button btnTaskList;
    @BindView(R.id.txt_HintInfo)
    TextView txtHintInfo;
    @BindView(R.id.gr_top)
    GridView grTop;
    @BindView(R.id.gr_bottom)
    GridView grBottom;
    @BindView(R.id.gr_place)
    GridView grPlace;
    DetailAdapter detailAdapter;
    List<ODetail> details = new ArrayList<>();

    private PopupWindow popupWindowBack;
    private OrderDetailAdapter orderDetailAdapter;
    private OrderBottomDetailAdapter orderBottomDetailAdapter;
    private List<OrderDetailBean> orderDetailBeans = new ArrayList<>();
    private List<OrderDetailBean> orderDetailBottomBeans = new ArrayList<>();

    String TAG = getClass().getSimpleName();
    String RackNo = "", CutNo = "", PlaceNo = "", OrderNo = "", IsBind = "", CPUID = "";

    private Handler mainHandler;
    String curLoginUserNo, curLoginUser, curServiceUrl = "", curServiceDir = "", curDepartNo, curDepart;
    private JSONArray clearJsonArray, detailJsonArray, TaiorJsonArray, ModelJsonArray;
    MainApplication mApp;

    public static final int MSG_STATION = 90011;
    public static final int MSG_TailorPlace = 90012;
    List<CutStation> cutStations = new ArrayList<>();
    StationAdapter stationAdapter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_call, null);
        ButterKnife.bind(this, view);
        MainActivity activity = (MainActivity) getActivity();
        mainHandler = activity.mainHandler;
        mApp = (MainApplication) getActivity().getApplication();

        //裁剪工位
        stationAdapter = new StationAdapter(getActivity(), cutStations);
        grPlace.setAdapter(stationAdapter);
        grPlace.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                CutNo = cutStations.get(i).getCutCode();
                //通过裁剪工位获取对应的库位信息
                searchBarcodeData("", "TailorPlace");
                grBottom.setSelection(-1);
            }
        });
        //面料区
        grTop.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int po, long l) {
                OrderNo = orderDetailBeans.get(po).getOrderNo();
                RackNo = orderDetailBeans.get(po).getLooseRackNo();
                PlaceNo = orderDetailBeans.get(po).getPlaceNo();
            }
        });
        //裁剪工位区
        grBottom.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int po, long l) {
                OrderNo = orderDetailBottomBeans.get(po).getOrderNo();
                RackNo = orderDetailBottomBeans.get(po).getLooseRackNo();
                PlaceNo = orderDetailBottomBeans.get(po).getPlaceNo();
            }
        });
        //加接口监听
        activity.setTransParamsListenerP(new MainActivity.OnTransParamsListenerP() {
            @Override
            public void TransParams(Map<String, Object> mParams) {
                if (mParams != null) {
                    try {
                        String paramComm = mParams.get("ParamComm").toString();
                        if (paramComm == "LoginParam") {
                            Log.d(TAG, "LoginParam------------------>1");
                            //传递登陆参数信息;
                            curLoginUserNo = mParams.get("LoginUserNo").toString();
                            curLoginUser = mParams.get("LoginUser").toString();
                            curServiceUrl = mParams.get("ServiceUrl").toString();
                            curServiceDir = mParams.get("ServiceDir").toString();
                            curDepartNo = mParams.get("DepartNo").toString();
                            curDepart = mParams.get("Depart").toString();
                            CPUID = mParams.get("CPUID").toString();
                            Log.d(TAG, "LoginParam------------------>2");
                            //获取面料松布区
                            //获取裁剪工位
                            searchBarcodeData("", "获取裁剪工位");
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        });

        return view;
    }

    //扫描
    private void searchBarcodeData(String BarcodeParam, String operType) {
//        playRingtone();
        //执行SQL过程
        String SqlComm = "Exec AGV_LooseCloth_CutScanBarcode @Barcode='" + BarcodeParam + "',@OPERTYPE='" + operType + "'" +
                ",@PrBarcode='',@FormType='" + TAG + "',@RackNo='" + RackNo + "',@CutNo='" + CutNo + "',@PlaceNo='" + PlaceNo + "'," +
                "@OrderNo='" + OrderNo + "',@IsBind='" + IsBind + "',@UserNo='" + curLoginUserNo + "'";
        ReadSQLData(SqlComm);
    }


    //直接连获取数据，与Handler配套使用;
    private void ReadSQLData(final String SQLComm) {
        Log.e("过程", SQLComm);
        Runnable run = new Runnable() {
            @Override
            public void run() {
                try {
                    JSONArray jsonArray = ToolUtil.QuerySQL2JSON(SQLComm);
                    Log.e("结果", "结果" + jsonArray);
                    if ((jsonArray != null) && (jsonArray.length() > 0)) {
                        if (jsonArray.optJSONObject(0).has("OperType") == true) {
                            //扫描信息
                            if (jsonArray.optJSONObject(0).getString("OperType").equals("ClearLooseCloth")) {
                                detailJsonArray = jsonArray;
                                Message msg = new Message();
                                msg.what = MSG_SCANBARCODE;
                                fragmentHandler.removeMessages(msg.what);
                                fragmentHandler.sendMessage(msg);
                            }
                            //查询面料区
                            if (jsonArray.optJSONObject(0).getString("OperType").equals("QueryOrderNo")) {
                                detailJsonArray = jsonArray;
                                Message msg = new Message();
                                msg.what = MSG_SEARCH;
                                fragmentHandler.removeMessages(msg.what);
                                fragmentHandler.sendMessage(msg);
                            }
                            //详情
                            if (jsonArray.optJSONObject(0).getString("OperType").equals("LoadDetailFabricNo")) {
                                detailJsonArray = jsonArray;
                                Message msg = new Message();
                                msg.what = MSG_DETAIL;
                                fragmentHandler.removeMessages(msg.what);
                                fragmentHandler.sendMessage(msg);
                            }
                            // 获取裁剪工位
                            if (jsonArray.optJSONObject(0).getString("OperType").equals("获取裁剪工位")) {
                                detailJsonArray = jsonArray;
                                Message msg = new Message();
                                msg.what = MSG_STATION;
                                fragmentHandler.removeMessages(msg.what);
                                fragmentHandler.sendMessage(msg);
                            }
                            //根据裁剪工位获取库位信息
                            if (jsonArray.optJSONObject(0).getString("OperType").equals("TailorPlace")) {
                                detailJsonArray = jsonArray;
                                Message msg = new Message();
                                msg.what = MSG_TailorPlace;
                                fragmentHandler.removeMessages(msg.what);
                                fragmentHandler.sendMessage(msg);
                            }

                        }
                        if (jsonArray.optJSONObject(0).has("SQLExcept") == true) {
                            Message message = new Message();
                            message.what = MSG_ERRMSG;
                            Bundle bundle = new Bundle();
                            bundle.putString("Hint", jsonArray.optJSONObject(0).getString("SQLMessage"));
                            message.setData(bundle);
                            fragmentHandler.sendMessage(message);
                        }

                    } else {
                        Message message = new Message();
                        message.what = MSG_ERRMSG;
                        Bundle bundle = new Bundle();
                        bundle.putString("Hint", "未返回任何数据!");
                        message.setData(bundle);
                        fragmentHandler.removeMessages(message.what);
                        fragmentHandler.sendMessage(message);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    Message message = new Message();
                    message.what = MSG_ERRMSG;
                    Bundle bundle = new Bundle();
                    bundle.putString("Hint", e.getMessage().toString());
                    message.setData(bundle);
                    fragmentHandler.sendMessage(message);
                }

            }

        };
        new Thread(run).start();

    }

    @SuppressLint("HandlerLeak")
    public Handler fragmentHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (msg != null) {
                int msgId = msg.what;
                switch (msgId) {
                    //呼叫
                    case MSG_CallAgvResult:
                        String tmpstr = msg.obj.toString();
                        try {
                            JSONObject jsonObject = new JSONObject(tmpstr);
                            if (jsonObject.has("status") && jsonObject.has("errorinfo")) {

                                txtHintInfo.setText(jsonObject.getString("errorinfo"));
                                if (jsonObject.getInt("status") == 0)
                                    txtHintInfo.setTextColor(getResources().getColor(R.color.green));
                                else
                                    txtHintInfo.setTextColor(getResources().getColor(R.color.red));
                            } else {
                                txtHintInfo.setText(msg.obj.toString());
                            }
                            if (jsonObject.has("data") && jsonObject.get("data") != null) {
                                String data = jsonObject.getString("data");
                                JSONArray jsonArray = new JSONArray(data);
                                /*jsonArray包含OperType,ReqCode,StartPlace,EndPlace,RowIndex,TaskCode,message,可以选择显示*/
                                if (jsonArray != null && jsonArray.length() > 0) {
                                    for (int i = 0; i < jsonArray.length(); i++) {
                                        JSONObject object = jsonArray.getJSONObject(i);
                                        if (object.has("TaskCode") && object.has("message")) {
                                            txtHintInfo.setText(object.getString("TaskCode") + ":" + object.getString("message")
                                                    + "\r\n" + txtHintInfo.getText().toString());
                                        }
                                    }
                                }
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        break;
                    case MSG_ERRMSG:
                        Bundle bundle1 = msg.getData();
                        String resultMsg = bundle1.getString("Hint");
                        AlertDialog alertDialog = new AlertDialog.Builder(getContext())
                                .setTitle("系统提示").setMessage(resultMsg)
                                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int which) {
                                    }
                                }).create();
                        alertDialog.show();
                        break;
                    //扫描
                    case MSG_SCANBARCODE:
                        fillScan();
                        break;
                    //查询面料区
                    case MSG_SEARCH:
                        if (detailJsonArray != null && detailJsonArray.length() > 0) {
                            List<OrderDetailBean> detailBeans = new Gson().fromJson(String.valueOf(detailJsonArray), new TypeToken<List<OrderDetailBean>>() {
                            }.getType());
                            orderDetailBeans.clear();
                            orderDetailBeans.addAll(detailBeans);
                            orderDetailAdapter = new OrderDetailAdapter(getActivity(), orderDetailBeans, FragmentP.this);
                            grTop.setAdapter(orderDetailAdapter);
                        } else {
                            grTop.setAdapter(null);
                        }
                        break;
                    //裁剪工位区
                    case MSG_TailorPlace:
                        if (detailJsonArray != null && detailJsonArray.length() > 0) {
                            List<OrderDetailBean> detailBeans = new Gson().fromJson(String.valueOf(detailJsonArray), new TypeToken<List<OrderDetailBean>>() {
                            }.getType());
                            orderDetailBottomBeans.clear();
                            orderDetailBottomBeans.addAll(detailBeans);
                            orderBottomDetailAdapter = new OrderBottomDetailAdapter(getActivity(), orderDetailBottomBeans, FragmentP.this);
                            grBottom.setAdapter(orderBottomDetailAdapter);
                        } else {
                            grBottom.setAdapter(null);
                        }
                        break;
                    //查询详情
                    case MSG_DETAIL:
                        Log.e(TAG, "MSG_DETAIL");
                        if (detailJsonArray != null && detailJsonArray.length() > 0) {
                            List<ODetail> detailBeans = new Gson().fromJson(String.valueOf(detailJsonArray), new TypeToken<List<ODetail>>() {
                            }.getType());
                            details.clear();
                            details.addAll(detailBeans);
                            Log.e(TAG, "details.size:" + details.size());
                            detailAdapter.notifyDataSetChanged();
                        } else {
                            details.clear();
                            detailAdapter.notifyDataSetChanged();
                        }
                        break;
                    //获取工位
                    case MSG_STATION:
                        if (detailJsonArray != null && detailJsonArray.length() > 0) {
                            List<CutStation> detailBeans = new Gson().fromJson(String.valueOf(detailJsonArray), new TypeToken<List<CutStation>>() {
                            }.getType());
                            cutStations.clear();
                            cutStations.addAll(detailBeans);
                            stationAdapter.notifyDataSetChanged();
                        } else {
                            cutStations.clear();
                            stationAdapter.notifyDataSetChanged();
                        }
                        //获取面料区
                        OrderNo = txtOrder.getText().toString();
                        searchBarcodeData("", "QueryOrderNo");
                        break;
                    default:
                        break;
                }
            }
        }
    };

    private void fillScan() {
        if (detailJsonArray != null && detailJsonArray.length() > 0) {
            try {
                if (detailJsonArray.getJSONObject(0).has("LoadDetailFabricNo") == true) {
                    if (detailJsonArray.getJSONObject(0).getString("LoadDetailFabricNo").equals("Y")) {
                        OrderNo = txtOrder.getText().toString();
                        searchBarcodeData("", "QueryOrderNo");
                    }
                }
                if (detailJsonArray.getJSONObject(0).has("ResultInfo") == true)
                    txtHintInfo.setText(detailJsonArray.getJSONObject(0).getString("ResultInfo"));
                if (detailJsonArray.getJSONObject(0).has("ErrInfo") == true) {
                    AlertDialog alertDialog = new AlertDialog.Builder(getActivity())
                            .setTitle("系统提示").setMessage(detailJsonArray.getJSONObject(0).getString("ErrInfo"))
                            .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    return;
                                }
                            }).create(); // 创建对话框
                    alertDialog.show(); // 显示对话框
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }


    @OnClick({R.id.btn_today_plan, R.id.tv_search, R.id.btn_refresh, R.id.btn_push_empty, R.id.btn_call_agv, R.id.btn_clear, R.id.btn_task_list})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            //查询合同
            case R.id.tv_search:
                OrderNo = txtOrder.getText().toString();
                searchBarcodeData("", "QueryOrderNo");
                break;
            //刷新数据
            case R.id.btn_refresh:
                break;
            //开始执行--》搬来满货架
            case R.id.btn_call_agv:
                if (!TextUtils.isEmpty(mApp.agvUrl)) {
                    PutAGVTask("开始执行");
                } else {
                    Toast.makeText(getActivity(), "请先配置agv地址", Toast.LENGTH_LONG).show();
                }
                break;
            //任务列表
            case R.id.btn_task_list:
                Intent mainActivity  = new Intent(getContext(), TaskSearchActivity.class);
                Bundle paramBundle = new Bundle();
                paramBundle.putString("LoginUserNo", curLoginUserNo);
                paramBundle.putString("PartName", "裁剪呼叫");
                paramBundle.putString("CurDepartNo", curDepartNo);
                mainActivity.putExtras(paramBundle);
                getActivity().startActivity(mainActivity);
                break;
            //日生产计划单
            case R.id.btn_today_plan:
                Intent mainActivity1  = new Intent(getContext(), ProductPlanActivity.class);
                Bundle paramBundle1 = new Bundle();
                paramBundle1.putString("LoginUserNo", curLoginUserNo);
                paramBundle1.putString("PartName", "裁剪呼叫");
                paramBundle1.putString("CurDepartNo", curDepartNo);
                mainActivity1.putExtras(paramBundle1);
                getActivity().startActivity(mainActivity1);
                break;
            //清空货架信息
            case R.id.btn_clear:
                searchBarcodeData("", "ClearLooseCloth");
                break;
            //货架回收--->搬走空货架
            case R.id.btn_push_empty:
                if (!TextUtils.isEmpty(mApp.agvUrl)) {
                    PutAGVTask("货架回收");
                } else {
                    Toast.makeText(getActivity(), "请先配置agv地址", Toast.LENGTH_LONG).show();
                }
                break;
        }
    }

    //调用Agv通用接口
    private void PutAGVTask(String OperType) {
        String SqlComm = "Exec AGV_LooseCloth_CutScanBarcode @Barcode='',@OPERTYPE='" + OperType + "'" +
                ",@PrBarcode='',@FormType='" + TAG + "',@RackNo='" + RackNo + "',@CutNo='" + CutNo + "',@PlaceNo='" + PlaceNo + "'," +
                "@OrderNo='" + OrderNo + "',@IsBind='" + IsBind + "',@UserNo='" + curLoginUserNo + "'";
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("sqlComm", SqlComm);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        System.out.println("PutAGVTask请求:" + MainApplication.agvUrl + "/api/hikAgv/callAgv");
        System.out.println("PutAGVTask参数:" + jsonObject.toString());
        //直接调用呼叫接口;
        BaseRequest.postJsonData(MainApplication.agvUrl + "/api/hikAgv/callAgv", jsonObject.toString(), fragmentHandler, MSG_CallAgvResult);
    }

    private void playRingtone() {
        Uri notification = Uri.parse("android.resource://" + getActivity().getPackageName() + "/" + R.raw.scan);
        Ringtone r = RingtoneManager.getRingtone(getActivity(), notification);
        r.play();
    }

    private void hideIM(View edt) {
        try {
            InputMethodManager im = (InputMethodManager) getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE);
            IBinder windowToken = edt.getWindowToken();
            if (windowToken != null) {
                im.hideSoftInputFromWindow(windowToken, 0);
            }
        } catch (Exception e) {

        }
    }

    @Override
    public void showDetail(int po) {
        DisplayMetrics metric = new DisplayMetrics();
        this.getActivity().getWindowManager().getDefaultDisplay().getMetrics(metric);
        int width = metric.widthPixels;
        int height = metric.heightPixels;
        View view = LayoutInflater.from(getActivity()).inflate(R.layout.pop_detail, null);
        popupWindowBack = new PopupWindow(view, width / 2, height / 2);
        view.findViewById(R.id.back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                popupWindowBack.dismiss();
            }
        });
        ListView lv = view.findViewById(R.id.lv);
        detailAdapter = new DetailAdapter(getActivity(), details);
        lv.setAdapter(detailAdapter);
        View head = LayoutInflater.from(getActivity()).inflate(R.layout.lv_detail_item_head, null);
        lv.addHeaderView(head);

        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                PlaceNo = details.get(i - 1).getPlaceNo();
                OrderNo = details.get(i - 1).getOrderNo();
                RackNo = details.get(i - 1).getLooseRackNo();
                popupWindowBack.dismiss();
            }
        });

        OrderNo = orderDetailBeans.get(po).getOrderNo();
        RackNo = orderDetailBeans.get(po).getLooseRackNo();
        PlaceNo = orderDetailBeans.get(po).getPlaceNo();

        searchBarcodeData("", "LoadDetailFabricNo");

        popupWindowBack.setFocusable(true);
        popupWindowBack.setTouchable(true);
        popupWindowBack.setBackgroundDrawable(new ColorDrawable());
        popupWindowBack.setOutsideTouchable(true);
        popupWindowBack.showAtLocation(view, Gravity.CENTER, 0, 0);
    }

    @Override
    public void Onclick(int position) {

    }

    @Override
    public void OnclickBottom(int position) {

    }

    @Override
    public void showDetailq(int po) {
        DisplayMetrics metric = new DisplayMetrics();
        this.getActivity().getWindowManager().getDefaultDisplay().getMetrics(metric);
        int width = metric.widthPixels;
        int height = metric.heightPixels;
        View view = LayoutInflater.from(getActivity()).inflate(R.layout.pop_detail, null);
        popupWindowBack = new PopupWindow(view, width / 2, height / 2);
        view.findViewById(R.id.back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                popupWindowBack.dismiss();
            }
        });
        ListView lv = view.findViewById(R.id.lv);
        detailAdapter = new DetailAdapter(getActivity(), details);
        lv.setAdapter(detailAdapter);
        View head = LayoutInflater.from(getActivity()).inflate(R.layout.lv_detail_item_head, null);
        lv.addHeaderView(head);

        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                PlaceNo = details.get(i - 1).getPlaceNo();
                OrderNo = details.get(i - 1).getOrderNo();
                RackNo = details.get(i - 1).getLooseRackNo();
                popupWindowBack.dismiss();
            }
        });

        OrderNo = orderDetailBottomBeans.get(po).getOrderNo();
        RackNo = orderDetailBottomBeans.get(po).getLooseRackNo();
        PlaceNo = orderDetailBottomBeans.get(po).getPlaceNo();

        searchBarcodeData("", "LoadDetailFabricNo");

        popupWindowBack.setFocusable(true);
        popupWindowBack.setTouchable(true);
        popupWindowBack.setBackgroundDrawable(new ColorDrawable());
        popupWindowBack.setOutsideTouchable(true);
        popupWindowBack.showAtLocation(view, Gravity.CENTER, 0, 0);
    }
}
